﻿using System.ComponentModel.Composition.Hosting;
using System.Windows;
using AvalonDock.Layout;
using DevExpress.Xpf.Docking;
using JXPlatform.Demo.Views;
using JXPlatform.GIS;
using JXPlatform.Infrastructure;
using JXPlatform.Infrastructure.Models;
using JXPlatform.Infrastructure.RegionAdapters;
using Microsoft.Practices.Prism.MefExtensions;
using Microsoft.Practices.Prism.Modularity;
using System.ComponentModel.Composition;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.ServiceLocation;

namespace JXPlatform.Demo
{
    public class DemoBootstrapper : MefBootstrapper
    {
        private readonly CallbackLogger _callbackLogger = new CallbackLogger();

        protected override DependencyObject CreateShell()
        {
            return ServiceLocator.Current.GetInstance<Shell>();
        }

        protected override void InitializeShell()
        {
            Application.Current.MainWindow = (Shell)Shell;
            Application.Current.MainWindow.Show();
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new ConfigurationModuleCatalog();
        }

        protected override void ConfigureAggregateCatalog()
        {
            AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(DemoBootstrapper).Assembly));
            AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ModuleInfrastructure).Assembly));
            AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ModuleGis).Assembly));

            //var catalog = new DirectoryCatalog("Modules");
            //AggregateCatalog.Catalogs.Add(catalog);
        }

        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();

            Container.ComposeExportedValue(_callbackLogger);
        }

        protected override Microsoft.Practices.Prism.Logging.ILoggerFacade CreateLogger()
        {
            return _callbackLogger;
        }

        protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
        {
            var instance = base.ConfigureRegionAdapterMappings();
            instance.RegisterMapping(typeof(LayoutDocumentPane), ServiceLocator.Current.GetInstance<LayoutDocumentPaneRegionAdapter>());
            instance.RegisterMapping(typeof(DocumentGroup), ServiceLocator.Current.GetInstance<DocumentGroupRegionAdapter>());

            return instance;
        }
    }
}
